<template>
	<view>
		<view class="list" v-if="list && list.length">
			<view class="item" v-for="(item, index) in list" :key="index">
				<view class="item-head">
					<view class="title">{{item.name || ''}}</view>
					<view class="postal">邮编号：{{item.zip_code || ''}}</view>
				</view>
				<view class="contact">
					<view class="contact-info">
						<text class="surname">{{item.username || ''}}（{{item.role_number}}）</text>
						<text class="telephone">{{item.contact_number || ''}}</text>
					</view>
					<view class="copy-btn" @click="copyStr(item)">复制</view>
				</view>
				<view class="address">
					<image class="img" src="/static/images/location.png" mode="widthFix"></image>
					<view class="txt">{{item.province}} {{item.city}} {{item.district}} {{item.address || ''}}-{{item.role_number || ''}}{{item.username || ''}}转{{item.contacts}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {warehouseFaceListApi} from '@/api/index.js';
	export default {
		data() {
			return {
				list: []
			};
		},
		onLoad() {
			this.warehouseFaceList();
		},
		methods: {
			async warehouseFaceList(){
				try{
					
					let response = await warehouseFaceListApi();
					if(response.status === 200){
						let list = response.data.warehouse,
							listLength = list.length;
						if(listLength === 0){
							return ;
						}
						this.list = list;
					}
				
				}catch(e){
					console.log(e);
					uni.showToast({title: e.message,icon: 'none'});
				}
				
			},
			copyStr(item) {
				let str = `收件人：${item.username}(${item.role_number});聯繫電話：${item.contact_number};郵編號碼：${item.zip_code}收件地址：${item.province} ${item.city} ${item.district} ${item.address}-${item.role_number || ''}${item.username}转${item.contacts}`;
				uni.setClipboardData({
					data: str
				});
			}
		}
	}
</script>

<style lang="scss">
	.list {
		width: 100%;
		padding: 30rpx;
		box-sizing: border-box;
		
		.item {
			margin-bottom: 20rpx;
			background-color: #fff;
			border-radius: 20rpx;
			box-shadow: 2rpx 2rpx 28rpx 0 rgba(0,0,0,0.06);
			padding: 30rpx;
			box-sizing: border-box;
			width: 100%;
			
			.item-head {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-bottom: 25rpx;
				border-bottom: 2rpx solid rgba(0, 0, 0, .2);
				box-sizing: border-box;
				
				.title {
					color: #E6201A;
					font-size: 32rpx;
					font-weight: bold;
				}
				
				.postal {
					width: 240rpx;
					height: 52rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					background-color: #FAFAFA;
					border-radius: 52rpx 0 0 52rpx;
					font-size: 24rpx;
					color: #9a9a9a;
					font-weight: bold;
					transform: translateX(30rpx);
				}
			}
			
			.contact {
				padding-top: 20rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				
				.contact-info {
					display: flex;
					align-items: center;
					justify-content: flex-start;
					
					.surname {
						font-size: 32rpx;
						color: #333;
						font-weight: bold;
					}
					
					.telephone {
						padding-left: 28rpx;
						font-size: 26rpx;
						color: #9a9a9a;
						font-weight: 500;
					}
				}
				
				.copy-btn {
					width: 76rpx;
					height: 40rpx;
					box-sizing: border-box;
					display: flex;
					align-items: center;
					justify-content: center;
					border-radius: 8rpx;
					border: 2rpx solid rgba(#E6201A, .2);
					font-size: 24rpx;
					color: #E6201A;
					font-weight: 500;
				}
			}
			
			.address {
				padding-top: 15rpx;
				display: flex;
				align-items: center;
				justify-content: flex-start;
				
				.img {
					width: 20rpx;
					height: 26rpx;
				}
				
				.txt {
					padding-left: 10rpx;
					font-size: 28rpx;
					font-weight: 500;
					color: #666;
				}
			}
		}
		
		.item:last-child {
			margin-bottom: 0;
		}
	}
</style>
